
/* Generated by Interface Builder */

#import "Math.h"
#import <appkit/Form.h>
#import <stdio.h>

#define MAXINT 2147483649

extern int getRand(int MaxVal);

@implementation Math

+ new
{
	self = [super new];
	maxNumber = 10;
	firstLine = getRand(maxNumber);
	secondLine = getRand(maxNumber);	
	return self;
}

- setFirstLineText:anObject
{
    firstLineText = anObject;
    [firstLineText setIntValue:firstLine];
    return self;
}

- setSecondLineText:anObject
{
    secondLineText = anObject;
    [secondLineText setIntValue:secondLine];
    return self;
}

- setMaxNumberText:anObject
{
    maxNumberText = anObject;
    return self;
}

- setOperand:anObject
{
    operand = anObject;
    [operand setStringValue:"+"];
    return self;
}

- Input:sender
{
int answer, panelReply;
	answer = [sender intValue];
	if (answer == firstLine + secondLine) {
		panelReply = NXRunAlertPanel("Professor Gonk-u-lator says",
					"That is right!", "Another", "Harder", "Easier");
		if (panelReply == 0) {
			if (maxNumber < MAXINT/2) maxNumber *= 2;
		}
		if (panelReply == -1) {
			if (maxNumber > 2) maxNumber /= 2;
		}
		[maxNumberText setIntValue:maxNumber];
		
		[sender setStringValue:""];
		[sender selectTextAt:0];
		firstLine = getRand(maxNumber);
 		[firstLineText setIntValue:firstLine];
		secondLine = getRand(maxNumber);
		[secondLineText setIntValue:secondLine];
	} else {
		panelReply = NXRunAlertPanel("Professor Gonk-u-lator says",
					"Sorry - try again", "Another Try",
					"Hint", "Quit");
	[sender selectTextAt:0];
		if (panelReply == -1) {
			exit(0);
		}
	}
	return self;
}


@end
